/**
 *
 */

package com.moogene.saad.sns;

import com.moogene.android.InfoMediator;
import com.moogene.android.R;

import android.graphics.Bitmap;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 28850924
 *
 */
public class Session {
    private static Session session = new Session();

    private String username;

    private String password;

    private String displayName;

    private String sex;

    private Bitmap gravator;

    private List<Friend> friends = new ArrayList<Friend>();
    private List<Friend> ContactFriends = new ArrayList<Friend>();

    public static Session getSession() {
        return session;
    }

    public static boolean login(String user, String pass) {
        return session.auth(user, pass);
    }

    public static void logout(String user) {
        session.logout();
        session = null;
    }

    public List<Friend> getFriends() {
        return friends;
    }

    public Bitmap getGravator() {
        return gravator;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @return the displayName
     */
    public String getDisplayName() {
        return displayName;
    }

    /**
     * @return the sex
     */
    public String getSex() {
        return sex;
    }

    private void logout() {
        gravator.recycle();
        gravator = null;

    }

    private boolean auth(String user, String pass) {
        // TODO: fake auth
        username = user;
        password = pass;
        displayName = "Fake User";
        sex = "male";
        if (gravator != null) {
            gravator.recycle();
        }
        gravator = InfoMediator.getBitmap(R.drawable.default_gravator);
        loadFriends();
        return true;
    }

    private boolean loadFriends() {
        for (int i = 0; i < 50; i++) {
            Friend friend = new Friend("fakefriend", "Male", "fake",
                    "test@abc.com", InfoMediator.getBitmap(R.drawable.android));
            friends.add(friend);
        }
        return true;
    }
}
